package cryptx

import (
	"codeup.aliyun.com/lsxd/zltx/adapter/utils/cryptx/sm2"
	"codeup.aliyun.com/lsxd/zltx/adapter/utils/formater"
	stdSm2 "github.com/emmansun/gmsm/sm2"
)

type sm2Builder struct {
	base *sm2.Options
}

// SetFormat 设置数据格式，默认是base64
func (b *sm2Builder) SetFormat(f formater.Formater) *sm2Builder {
	b.base.SetFormat(f)
	return b
}

// SetKeyType 设置密钥格式，默认是hex
func (b *sm2Builder) SetKeyType(t sm2.KeyType) *sm2Builder {
	b.base.SetKeyType(t)
	return b
}

// SetPrivateKey 设置私钥
func (b *sm2Builder) SetPrivateKey(key string) *sm2Builder {
	b.base.SetPrivateKey(key)
	return b
}

// SetPublicKey 设置公钥
func (b *sm2Builder) SetPublicKey(key string) *sm2Builder {
	b.base.SetPublicKey(key)
	return b
}

// SetEncryptOpts 设置加密选项，默认是ASN1EncrypterOpts
func (b *sm2Builder) SetEncryptOpts(m *stdSm2.EncrypterOpts) *sm2Builder {
	b.base.SetEncryptOpts(m)
	return b
}

// SetDecryptOpts 设置解密选项，默认是ASN1DecrypterOpts
func (b *sm2Builder) SetDecryptOpts(m *stdSm2.DecrypterOpts) *sm2Builder {
	b.base.SetDecryptOpts(m)
	return b
}

// Build 构建加密器
func (b *sm2Builder) Build() Crypto {
	d := sm2.NewSm2(b.base)
	return d
}
